// coordconv.cpp

#include "coordconv.h"

coordconv::coordconv()
{

}

coordconv& coordconv::operator= (const coordconv &ccSource)
{
    // check for self-assignment by comparing the address of the
    // implicit object and the parameter
    if (this == &ccSource)
        return *this;

    // do the copy
    xmin = ccSource.xmin;
    xmax = ccSource.xmax;
    ymin = ccSource.ymin;
    ymax = ccSource.ymax;
    vxmin = ccSource.vxmin;
    vxmax = ccSource.vxmax;
    vymin = ccSource.vymin;
    vymax = ccSource.vymax;
    MAX_X = ccSource.MAX_X;
    MAX_Y = ccSource.MAX_Y;

    // return the existing object
    return *this;
}


void coordconv::WindowtoViewPort(double &x, double &y)
{
    double viewx;
    double viewy;
    double worldx;
    double worldy;

    // double transformation from world to viewport to screen

    viewx = ((x - xmin)/(xmax - xmin))*(vxmax - vxmin) + vxmin;
    viewy = ((y - ymin)/(ymax - ymin))*(vymax - vymin) + vymin;
    //converts from window coords to viewport coords
        worldx = (viewx * (MAX_X/2))+(MAX_X/2);
        worldy = (viewy * (-1 * MAX_Y/2))+(MAX_Y/2);

/*        worldx = ((viewx - vxmin)/(vxmax - vxmin)) * (MAX_X - 0) + 0;
        worldy = ((viewy - vymin)/(vymax - vymin)) * (0 - MAX_Y) + MAX_Y;
*/
        // converts from veiwport coords to device pixels

    x = worldx;
    y = worldy;
}
